package com.sino.operation.system.controller;

import com.sino.operation.commons.response.CenterResponseEntity;
import com.sino.operation.entity.BizField;
import com.sino.operation.service.BizFieldManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("fieldManager")
@Api(value = "字段管理接口", tags = "字段管理接口")
public class FieldManagerController {

    @Autowired
    private BizFieldManagerService bizFieldManagerService;

    @GetMapping("/selectFiledList")
    @ApiOperation(value = "查询字段列表")
    @ResponseBody
    public List<BizField> getFieldList(@RequestParam("filedCN") String filedCN){

        return bizFieldManagerService.selectList(filedCN);
    }

    @PostMapping("/addFiled")
    @ApiOperation(value = "新增字段")
    @ResponseBody
    public CenterResponseEntity addField(BizField bizField){
        try {
            bizFieldManagerService.saveOrUpdate(bizField);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CenterResponseEntity.build();
    }

    @PostMapping("/deleteField")
    @ApiOperation(value = "批量删除字段")
    @ResponseBody
    public CenterResponseEntity deleteField(List ids){
        try {
            bizFieldManagerService.removeByIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }


    @PostMapping("/updateField")
    @ApiOperation(value = "修改字段信息")
    @ResponseBody
    public CenterResponseEntity updateField(BizField sysField){
        try {
            bizFieldManagerService.saveOrUpdate(sysField);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }
}
